<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\base\CurrencyModel;
use App\Models\CustomerModel;
use App\Models\FlightModel;
use App\Models\TakeOrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;


class ReceivableGenericDetailModel extends BaseModel
{
    use HasFactory;

    protected $table = 't_receivable_generic_detail';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 收款状态
    const STATUS_UNPAID = 1; // 未收款
    const STATUS_PARTIAL_PAID = 2; // 部分收款
    const STATUS_PAID = 3; // 已收款
    
    const STATUS_MAPS = [
        self::STATUS_UNPAID => '未收款',
        self::STATUS_PARTIAL_PAID => '部分收款',
        self::STATUS_PAID => '已收款',
    ];

    // 关联提单
    public function take_order(): BelongsTo
    {
        return $this->belongsTo(TakeOrderModel::class, 'take_order_id');
    }

    // 关联航班
    public function flight(): BelongsTo
    {
        return $this->belongsTo(FlightModel::class, 'flight_id');
    }

    // 关联客户
    public function customer(): BelongsTo
    {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    // 创建人
    public function create_admin(): BelongsTo
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //币种
    public function currency(): BelongsTo {
        return $this->BelongsTo(CurrencyModel::class, 'currency_id');
    }


} 